from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy import Integer, String, SmallInteger
from ..database.db import Base

class Voices(Base):
    """
    Voices Model
    """
    __tablename__ = 'voices'

    id : Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    name : Mapped[str] = mapped_column(String(255), nullable=False)
    path : Mapped[str] = mapped_column(String(255), nullable=False)
    type : Mapped[int] = mapped_column(SmallInteger, nullable=True)
    oss_url : Mapped[str] = mapped_column(String(255), nullable=True)
    def as_dict(self):
        """将对象转换为字典"""
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

    def __repr__(self):
        return f"<Voices(id={self.id}, name='{self.name}', path='{self.path}')>"
